#!/bin/sh

#
# Initialize Service Agent
#

# Ensure DISPLAY is set
if [ -z "$DISPLAY" ]
then

  # Stanimir Stanev, Jun 28, 2001
  # get an argument and set the DISPLAY. We are using this from the WebSM
  # parse command options
  set -- `getopt d: "$@"`
  # go through all command arguments
  while [ $# -gt 0 ]
  do
    case "$1" in
      -d)  export DISPLAY="$2"; shift;;
      --)  shift; break;;
       *)  break;;         # terminate while loop
    esac
    shift
  done

  if [ -z "$DISPLAY" ]
  then
    echo "$0: Display variable DISPLAY is not set."
    exit 1
  fi

fi

unset CLASSPATH
unset JAVA_HOME

for f in /usr/svcagent/lib/*jar
do
  export CLASSPATH=$CLASSPATH:$f
done
export PATH=$PATH:/usr/svcagent/bin:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:/local/bin:/usr/dt/bin:/opt/IBMJava2-13/bin:/usr/java130/bin:/opt/IBMJava2-13/jre/bin
#export JAVA_COMPILER=NONE
cd /var/svcagent

# Check if the License Agreement is Accepted by the user
#if [ -f /var/svcagent/IBMLicense ]
#then
#  java com.ibm.ecf.apps.LicenseAgreement
#fi
# If the License Screen is already shown, check if it is accepted by the user or not
#if [ ! -f /var/svcagent/IBMLicense.accept ]
#then
#  echo "$0: License is NOT accepted. Cannot Continue the Service Agent Program."
#  exit 1
#fi

# Check if the License Agreement is Accepted by the user
java com.ibm.ecf.apps.LicenseAgreementWSM
if [ ! -f $HOME"/sa.acp" ]
then
  echo "License is NOT accepted. Cannot Continue the Service Agent Program."
  exit 1
fi

echo "Starting ServiceAgent..."

bc=""
bc=`java com.ibm.ecf.apps.Bcp`

#java $bc com.ibm.sa.apps.SAUI
nohup java $bc com.ibm.sa.apps.SAUI >/dev/null 2>&1 &
#nohup java $bc com.ibm.sa.apps.SAUI >/dev/null 2>&1 &
#nohup java $bc com.ibm.sa.apps.SAUI >/var/svcagent/logs/log.saui 2>&1 &
#sleep 2
